Skip to content

feat: add prefix option for authentication routes#1322

Open
dimtrovich wants to merge 4 commits into
codeigniter4:developfrom
dimtrovich:feat/prefix-options-to-routes
Open

feat: add prefix option for authentication routes#1322
dimtrovich wants to merge 4 commits into
codeigniter4:developfrom
dimtrovich:feat/prefix-options-to-routes

Conversation

@dimtrovich
Copy link
Copy Markdown

@dimtrovich dimtrovich commented Apr 20, 2026

Description

This pull request adds the ability to prefix all authentication route paths using a new prefix option in the routes() method.

  • New prefix option: Allows you to define a common prefix for all authentication routes (default /)
  • Refactoring: Replaces the hard-coded route group ‘/’ with a configurable $prefix variable

Benefits of this change

  • Increased flexibility - Allows you to group auth routes under a single prefix (e.g., auth/login, auth/register)
  • Better organization - Facilitates the organization of routes in complex applications
  • Consistency - Complements the existing namespace and except options
  • Backward compatible - The default value / preserves the existing behavior

Usage example

// All routes will be prefixed with ‘auth’
service(‘auth’)->routes($routes, [‘prefix’ => ‘auth’]);

// Generates: auth/login, auth/register, auth/logout, etc.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn
Copy link
Copy Markdown
Member

This makes sense. However, could we rename prefix to group? It would better align with the underlying method we use.

@dimtrovich
Copy link
Copy Markdown
Author

This makes sense. However, could we rename prefix to group? It would better align with the underlying method we use.

done

@michalsn
Copy link
Copy Markdown
Member

Please rebase your branch onto upstream/develop. If you don't have an upstream remote configured, add it first and then run:

git rebase upstream/develop

@datamweb datamweb added the GPG-Signing needed Pull requests that need GPG-Signing label Apr 23, 2026
@dimtrovich dimtrovich force-pushed the feat/prefix-options-to-routes branch from abd414d to a1384fa Compare April 27, 2026 17:16
@michalsn
Copy link
Copy Markdown
Member

michalsn commented May 8, 2026

It looks like your branch was updated by merging/adding commits from develop, so this PR now includes unrelated commits:

Those should not be part of this PR. Please rebase your branch on top of the latest develop instead, and sign your commits while rewriting them.

If you do not already have the main Shield repository added as upstream, add it first:

git remote add upstream https://github.com/codeigniter4/shield.git
git fetch upstream

Then rebase your branch:

git checkout feat/prefix-options-to-routes

# optional safety backup
git branch backup/feat-prefix-options-to-routes

git rebase -i --rebase-merges --exec "git commit --amend --no-edit -S" upstream/develop

In the interactive rebase, drop the unrelated commits listed above if they appear. Keep only the commits that belong to this PR.

Then force-push the cleaned branch:

git push --force-with-lease origin feat/prefix-options-to-routes

Please use rebase rather than merging develop into the PR branch, so the PR only contains your changes.

@dimtrovich dimtrovich force-pushed the feat/prefix-options-to-routes branch from a1384fa to cc46a67 Compare May 12, 2026 10:39
@datamweb datamweb removed the GPG-Signing needed Pull requests that need GPG-Signing label May 13, 2026
@datamweb
Copy link
Copy Markdown
Collaborator

@dimtrovich Thanks for the PR!

Previously, we encouraged users to handle this via standard route groups like so:

$routes->group('accounts', static function($routes) {
    service('auth')->routes($routes);
});

However, this new group option is a great shorthand.

Could you please add a quick reminder to the docs regarding filters? Something like:

Note: If you have grouped or changed the default route format, ensure your paths match the new format in the app/Config/Filters.php file.

@datamweb datamweb added the enhancement New feature or request label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants